#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int cnt[10005];
int ans[N];
int get_sum(int x) {
  static int a[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int res = 0;
  while (x) {
    res += a[x % 10];
    x /= 10;
  }
  return res;
}
void init() {
  rep(i, 1, 1e4) {
    cnt[i] = get_sum(i);
    if (ans[cnt[i]] == 0) ans[cnt[i]] = i;
  }
  ans[0] = ans[1] = -1;
}
void solve(int x) {
  if (x <= 28) {
    cout << ans[x] << endl;
    return;
  }
  int y = x / 7 - 3;
  int z = 21 + x % 7;
  cout << ans[z];
  rep(i, 1, y) cout << 8;
  cout << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init();
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    solve(x);
  }
  return 0;
}